<?php include _include(APP_PATH.'view/htm/header.inc.htm');?>

<!--{hook user_create_start.htm}-->

<div class="row">
	<div class="col-lg-6 offset-lg-3">
		<!--{hook user_create_card_before.htm}-->
		<div class="card card-block">
			<h4 class="card-title">
				<?php echo lang('user_create');?>
				<!--{hook user_create_title_after.htm}-->
			</h4>
			<form action="<?php echo url('user-create');?>" method="post" id="form">
				<p class="input-group">
					<span class="input-group-addon"><i class="icon icon-envelope"></i></span>
					<input type="email" class="form-control" placeholder="<?php echo lang('email');?>" name="email" id="email" required>
				</p>
				<!--{hook user_create_email_after.htm}-->
				<p class="input-group">
					<span class="input-group-addon"><i class="icon icon-user"></i></span>
					<input type="text" class="form-control" placeholder="<?php echo lang('username');?>" name="username" id="username">
				</p>
				<!--{hook user_create_username_after.htm}-->
				<dl class="row">
					<dt style="width: 68%">
						<p class="input-group">
							<span class="input-group-addon"><i class="icon icon-lock"></i></span>
							<input type="password" class="form-control" placeholder="<?php echo lang('init_pw');?>" name="password" id="password">
						</p>
					</dt>
					<dd class="text-right vtop">
						<?php if($conf['user_create_email_on']) { ?>
						<button type="submit" class="btn btn-primary btn-sm m-l-1" id="sendinitpw" data-loading-text="<?php echo lang('sending');?>..." action="<?php echo url('user-sendinitpw');?>"><?php echo lang('get_init_pw');?></button>
						<?php } else { ?>
						<small class="hidden-sm-down"><?php echo lang('send_init_pw_tips');?></small>
						<?php } ?>
					</dd>
				</dl>
				<!--{hook user_create_password_after.htm}-->
				<p>
					<button type="submit" class="btn btn-primary btn-block" id="submit" data-loading-text="<?php echo lang('submiting');?>..." <?php if($conf['user_create_email_on']) { ?>disabled<?php } ?>><?php echo lang('next_step');?></button>
				</p>
				<!--{hook user_create_submit_after.htm}-->
				<dl class="row">
					<dt>
						<!--{hook user_create_form_footer_left.htm}-->
					</dt>
					<dd class="text-right">
						<!--{hook user_create_form_footer_right_start.htm}-->
						<a href="<?php echo url('user-login');?>" class="text-muted"><small><?php echo lang('user_login');?></small></a>
						<a href="<?php echo url('user-resetpw');?>" class="text-muted m-l-1"><small><?php echo lang('forgot_pw');?></small></a>
						<!--{hook user_create_form_footer_right_end.htm}-->
					</dd>
				</dl>
			</form>
		</div>
		<!--{hook user_create_card_after.htm}-->
	</div>
</div>

<!--{hook user_create_end.htm}-->

<?php include _include(APP_PATH.'view/htm/footer.inc.htm');?>

<script src="<?php echo $conf['view_url'];?>js/md5.js"></script>

<script>
var jform = $('#form');
var jsubmit = $('#submit');
var jsendsubmit = $('#sendinitpw');
var referer = '<?php echo http_referer();?>';
jsendsubmit.on('click', function() {
	jform.reset();
	jsendsubmit.button('loading');
	var postdata = jform.serialize();
	$.xpost(jsendsubmit.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			alert(message);
			$('#password').focus();
			var t = 60; // 倒计时
			jsendsubmit.button('<?php echo lang('user_send_sucessfully');?> 60 ');
			jsubmit.button('reset');
			// 倒计时，重新发送
			var handler = setInterval(function() {
				jsendsubmit.button('<?php echo lang('user_send_sucessfully');?> '+(--t)+' ');
				if(t == 0) {
					clearInterval(handler);
					jsendsubmit.button('reset');
				}
			}, 1000);
		} else if(code < 0) {
			alert(message);
			jsendsubmit.button('reset');
		} else {
			jform.find('[name="'+code+'"]').alert(message).focus();
			jsendsubmit.button('reset');
		}
	});
	return false;
});

jform.on('submit', function() {
	var postdata = jform.serializeObject();
	jsubmit.button('loading');
	postdata.password = $.md5(postdata.password);
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			$.alert(message);
			jsubmit.button(message).delay(3000).location(referer);
		} else if(code < 0) {
			$.alert(message);
			jsubmit.button('reset');
		} else {
			jform.find('[name="'+code+'"]').alert(message).focus();
			jsubmit.button('reset');
		}
	});
	return false;
});

</script>

<!--{hook user_create_js.htm}-->